/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
//作者:AKPower
//算法:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const ll maxn = 1e6 + 100;
ll prime[maxn];
//线性筛
void init_prime()
{
    ll n = 1e6;
    for (ll i = 2; i <= n; i++)
    {
        if (!prime[i])
        {
            prime[++prime[0]] = i;
        }
        for (ll j = 1; j <= prime[0] && i * prime[j] <= n; j++)
        {
            prime[i * prime[j]] = i;
            if (i % prime[j] == 0)
                break;
        }
    }
    return;
}
//判断回文数
bool judge(ll n)
{
    ll temp1 = n;
    ll temp2 = 1;
    while (n)
    {
        temp2 = temp2 * 10 + n % 10;
        n /= 10;
    }
    while (temp1)
    {
        if (temp1 % 10 != temp2 % 10)
            return false;
        temp1 /= 10;
        temp2 /= 10;
    }
    return true;
}

int main()
{
    IOS;
    init_prime();
    ll L, R;
    cin >> L >> R;
    ll ans = 0;
    //第一个大于等于L的素数
    ll l = lower_bound(prime + 1, prime + prime[0] + 1, L) - prime;
    // 第一个大于R的素数
    ll r = upper_bound(prime + 1, prime + prime[0] + 1, R) - prime;
    for (ll i = l; i < r; i++)
    {
        if (judge(prime[i]))
            ans++;
    }
    cout << ans << endl;
    getchar();
    getchar();
    return 0;
}
